package com.cci.kangdao.dao;

import com.cci.kangdao.dao.model.NotifyRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public interface NotifyRecordTDao {




	/**
	 * 根据用户id和Category获取消息推送集合
	 * @param type
	 * @return
	 */
	public List<Map<String, Object>> getNotifyRecordTListByUserIdCategory(Map<String, Object> map);


	/**
	 * 根据用户id获取所有未读消息推送总数
	 * @param type
	 * @return
	 */

	@Select("select count(nr.ID) from NotifyRecord_T nr,WorkOrder_T wo " +
			"where wo.Flag = 0 and wo.ID = nr.OrderId and nr.ReceiverId= #{receiverId} and nr.SendType=2 and nr.Flag=0 and nr.IsRead=0")
	public int getIsReadNotifyRecordTNumByUserId(Map<String, Object> map);

	/**
	 * 根据用户id获取所有未读消息推送总数
	 * @param type
	 * @return
	 */
	@Update("update NotifyRecord_T set IsRead = 1,Updator=#{Updator},UpdateTime=#{UpdateTime} where ID = #{ID} ")
	public int updateNotifyRecordTById(Map<String, Object> map);

	@Update("update NotifyRecord_T set IsRead = 1, Updator = #{updator}, UpdateTime = #{updateTime} where IsRead = 0 and ReceiverId = #{receiverId} ")
	int updateNotifyReadStatusByReceiver(@Param("receiverId") Long ReceiverId, @Param("updator") Long updator, @Param("updateTime") String updateTime);

	@Update("update NotifyRecord_T set IsRead = 1,Updator=#{Updator},UpdateTime=#{UpdateTime} where OrderId = #{orderId} and ReceiverId=#{receiverId}")
	public int updateNotifyRecordTByOrderId(Map<String, Object> map);

	List<Map<String,Object>> selectOrderRecordList(Map<String,Object> map);

	int saveNotifyRecord(NotifyRecord notifyRecord);


	List<Map<String, Object>> getWorkOrderNotifyRecordList(Long receiverId);

	@Update("update NotifyRecord_T set IsRead = 1,Updator=#{Updator},UpdateTime=#{UpdateTime} where ReceiverId = #{receiverId} and IsRead = 0")
	int updateNotifyRecordTByReceiverId(Map<String,Object> map);
}
